<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class CompanyController extends HomeController {

	//公司设置首页
    public function index()
    {        
        // echo "<pre>";
        // print_r($_SESSION);
        // echo "<pre>";
        // print_r($_SESSION);
      
        $this->display();
    }
   
   //公司添加联系方式
    public function index_lianxi()
    {
        $this->display();
    }


  //logo页面
    public function index_logo()
    {
        $this->display();
    }


   //公司描述
    public function index_description()
    {
        $this->display();
    }




// ======================================================================
    //注册公司信息
    public function add()
    {   
        if(stripos($_SERVER["HTTP_USER_AGENT"],"firefox")){ //为了兼容火狐 

                  // echo "<pre>";
                  // print_r($_SESSION);
                  // die;



                  $_POST['uid']               =  $_SESSION['onethink_home']['user_auth']['uid'];
                  $model                      =  M("Company");
                  $id                         =  $model->add($_POST);
                  $_SESSION['company']['cid'] =  $id;
               
                  if($id    == null)
                  {
                       //return false;
                        $this->display("Company/index");
                  }else{
                      // print_r($_SESSION);
                     $this->display("Company/index_lianxi");
                  }




        }else{

                  $_POST['uid']               =  $_SESSION['home']['user_auth']['uid'];
                  $model                      =  M("Company");
                  $id                         =  $model->add($_POST);
                  $_SESSION['company']['cid'] =  $id;
              
                  if($id    == null)
                  {
                       //return false;
                        $this->display("Company/index");
                  }else{
                      // print_r($_SESSION);
                     $this->display("Company/index_lianxi");
                  }
        } 
       









        // $_POST['uid']               =  $_SESSION['home']['user_auth']['uid'];
		
        // $model                      =  M("Company");
        // $id                         =  $model->add($_POST);
        // $_SESSION['company']['cid'] =  $id;
		
        // if($id    == null)
        // {
        //      //return false;
        //       $this->display("Company/index");
        // }else{
        //     // print_r($_SESSION);
        // 	  $this->display("Company/index_lianxi");
        // }
   
    } 

   //添加公司Logo 网站信息
       public function addlianxi()
       {
       
      if(stripos($_SERVER["HTTP_USER_AGENT"],"firefox")){ 
                      $_POST['cid'] = $_SESSION['company']['cid'];
                      $_POST['uid']               =  $_SESSION['onethink_home']['user_auth']['uid'];
                      $contact      = M("Contact");
                      $conid        = $contact->add($_POST);
                       // print_R($_POST);
                      // print_R($_SESSION);
                      // die;
                      if($conid     == null)
                       {
                        return false;
                        $this->error("111");
                       }else{

                        $this->display("Company/index_logo");
                       }
         
        }else{

                      $_POST['cid'] = $_SESSION['company']['cid'];
                      $_POST['uid']               =  $_SESSION['home']['user_auth']['uid'];
                      $contact      = M("Contact");
                      $conid        = $contact->add($_POST);
                       // print_R($_POST);
                      // print_R($_SESSION);
                      // die;
                      if($conid     == null)
                       {
                        return false;
                        $this->error("111");
                       }else{

                        $this->display("Company/index_logo");
                       }

        } 









        // $_POST['cid'] = $_SESSION['company']['cid'];
        // $_POST['uid']               =  $_SESSION['home']['user_auth']['uid'];
        // $contact      = M("Contact");
        // $conid        = $contact->add($_POST);
        //  // print_R($_POST);
        // // print_R($_SESSION);
        // // die;
        // if($conid     == null)
        //  {
        //   return false;
        //   $this->error("111");
        //  }else{

        //   $this->display("Company/index_logo");
        //  }
       }

    //添加公司Logo
       public function uploadPicture(){
        //TODO: 用户登录检测

        /* 返回标准数据 */
        $return  = array('status' => 1, 'info' => '上传成功', 'data' => '');

        /* 调用文件上传组件上传文件 */
        $Picture = D('Pic');
        $pic_driver = C('PICTURE_UPLOAD_DRIVER');
        $info = $Picture->upload(
            $_FILES,
            C('PICTURE_UPLOAD'),
            C('PICTURE_UPLOAD_DRIVER'),
            C("UPLOAD_{$pic_driver}_CONFIG")
        ); //TODO:上传到远程服务器

        /* 记录图片信息 */
        if($info){
            $return['status'] = 1;
            $return = array_merge($info['download'], $return);
        } else {
            $return['status'] = 0;
            $return['info']   = $Picture->getError();
        }

        /* 返回JSON数据 */
        $this->ajaxReturn($return);
    }



    public function addlogo()
    {
         // print_R($_POST);
         // print_r($_FILE);
         // die;
        







          if(stripos($_SERVER["HTTP_USER_AGENT"],"firefox")){ 
                                
                       // echo "<pre>";
                       // print_r($_SESSION);
                       echo "<pre>";
                       print_r($_SESSION);
                       $list['money_moshi']     =  $_POST['money_moshi'];
                       $list['money_hangye']    =  $_POST['money_hangye'].",".$_POST['money_hangye1'].",".$_POST['money_hangye2'];
                       $list['money_fanwei']    =  $_POST['money_fanwei'];
                       $list['money_chanpin']   =  $_POST['money_chanpin'];
                       $list['uid']             =  $_SESSION['onethink_home']['user_auth']['uid'];
                       $list['cid']             =  $_SESSION['company']['cid'];
                       $pic_id = $_SESSION['company']['pid'];
                        // print_r($list);
                        // print_r($pic_id);
                      echo $pic_id;
                       die;
                       $pic = M("pic");
                    
                       $id = $pic->where("id=".$pic_id)->save($list);
                        // print_R($id);
                        // die;
                       if($id == null)
                       {
                          $this->display("Company/index_logo");
                       }else{
                          $this->display("Company/index_description");
                       }
            }else{

                       $list['money_moshi']     =  $_POST['money_moshi'];
                       $list['money_hangye']    =  $_POST['money_hangye'].",".$_POST['money_hangye1'].",".$_POST['money_hangye2'];
                       $list['money_fanwei']    =  $_POST['money_fanwei'];
                       $list['money_chanpin']   =  $_POST['money_chanpin'];
                       $list['uid']             =  $_SESSION['home']['user_auth']['uid'];
                       $list['cid']             =  $_SESSION['company']['cid'];
                       $pic_id = $_SESSION['company']['pid'];
                   
                       $pic = M("pic");
                    
                       $id = $pic->where("id=".$pic_id)->save($list);
                     
                       if($id == null)
                       {
                          $this->display("Company/index_logo");
                       }else{
                          $this->display("Company/index_description");
                       }
           











            } 
       











         // $list['money_moshi']     =  $_POST['money_moshi'];
         // $list['money_hangye']    =  $_POST['money_hangye'].",".$_POST['money_hangye1'].",".$_POST['money_hangye2'];
         // $list['money_fanwei']    =  $_POST['money_fanwei'];
         // $list['money_chanpin']   =  $_POST['money_chanpin'];
         // $list['uid']             =  $_SESSION['home']['user_auth']['uid'];
         // $list['cid']             =  $_SESSION['company']['cid'];
         // $pic_id = $_SESSION['company']['pid'];
     
         // $pic = M("pic");
      
         // $id = $pic->where("id=".$pic_id)->save($list);
       
         // if($id == null)
         // {
         //    $this->display("Company/index_logo");
         // }else{
         //    $this->display("Company/index_description");
         // }

    }

    //  添加公司描述
    public function addescription()
    {
       // echo "<pre>";
       // print_R($_POST);
       // die;
       // print_r($_SESSION);
       $_POST['cid'] = $_SESSION['company']['cid'];
       $_POST['uid']               =   $_SESSION['home']['user_auth']['uid'];
       $description = M("description");
       // print_r($description);
       // print_R($_POST['cid']);
       $id          = $description->add($_POST);
       // die;
       if($id = null)
       {
          $this->error("简直");
       }else{
          $this->display("Product/index");
       }
    }
    
// ========================================================================

}